package com.douqu.game.main.server.rmi;

import com.douqu.game.core.config.challenge.LevelConfig;
import com.douqu.game.core.config.challenge.WorldBossConfig;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.database.model.PlayerModel;
import com.douqu.game.core.e.E_BattleDetailType;
import com.douqu.game.core.e.E_CityInOutType;
import com.douqu.game.core.e.E_PlayerLastUpdate;
import com.douqu.game.core.e.E_PlayerStatus;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.activity.DirectEndData;
import com.douqu.game.core.entity.activity.MatchBaseInfo;
import com.douqu.game.core.entity.battle.*;
import com.douqu.game.core.entity.common.TwoTuple;
import com.douqu.game.core.entity.ext.BagInfo;
import com.douqu.game.core.entity.ext.ChallengeInfo;
import com.douqu.game.core.entity.ext.SettingInfo;
import com.douqu.game.core.entity.ext.TaskInfo;
import com.douqu.game.core.entity.world.map.*;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.WorldInfoFactory;
import com.douqu.game.core.i.IMainServer;
import com.douqu.game.core.protobuf.SGChallengeProto;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.protobuf.SGMainProto;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.main.GameServer;
import com.douqu.game.main.database.mapper.read.ReadPlayerMapper;
import com.douqu.game.main.msg.ChallengeMsgChannel;
import com.douqu.game.main.msg.MajorMsgChannel;
import com.douqu.game.main.msg.param.StartBattleParam;
import com.douqu.game.main.server.ActivityCampManager;
import com.douqu.game.main.server.ServerManager;
import com.douqu.game.main.server.SpringContext;
import com.douqu.game.main.server.WorldManager;
import com.douqu.game.main.server.entity.ServerInfoBattle;
import com.douqu.game.main.util.WorldMapUtils;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by bean on 2017/7/19.
 */
public class MainServerImpl extends UnicastRemoteObject implements IMainServer {


    /**
     * 因为UnicastRemoteObject的构造方法抛出了RemoteException异常，因此这里默认的构造方法必须写，必须声明抛出RemoteException异常
     *
     * @throws RemoteException
     */
    public MainServerImpl() throws RemoteException {
    }

    @Override
    public void battleInit(int serverId, String battleId) throws RemoteException
    {
        LogUtils.info("战斗服务器已经收到主服务器发过去的初始化消息--->现在通知客户端去连接战斗服务器");

        ServerInfoBattle serverInfo = ServerManager.getInstance().getBattleServerInfo(serverId);
        if (serverInfo != null)
        {
            StartBattleParam startBattleParam = serverInfo.getStartBattleParam(battleId);
            if(startBattleParam != null)
            {
                LogUtils.debug("开始发送战斗服务器数据------------------>");

                startBattleParam.sendStartBattle();

                serverInfo.removeStartBattleParam(battleId);
            }
            else
            {
                LogUtils.error("startBattleParam 为空了 -> " + battleId);
            }
        }
        else
        {
            LogUtils.error("ServerInfo 为空 -> " + serverId);
        }
    }

    @Override
    public void battleStart(BattleDetail battleDetail) throws RemoteException
    {
        ServerInfoBattle serverInfo = ServerManager.getInstance().getBattleServerInfo(battleDetail.getServerId());
        if (serverInfo != null)
        {
            LogUtils.info("战斗服务器通知主服务器战斗开始 ->" + battleDetail.showInfo() + "  serverId -> " + battleDetail.getServerId());

            serverInfo.addBattle(battleDetail);

            WorldManager worldManager = GameServer.getInstance().getWorldManager();
            PlayerController playerController = worldManager.getPlayerController(battleDetail.getTeam1Info().getIndexInfo());
            if (playerController != null && playerController.getBattleData() != null)
            {
//                MsgUtils.sendWorldMapTaskChange(playerController, new CommonData(SGCommonProto.E_WORLDMAPTASK_TYPE.WORLD_MAP_TASK_KILL_CARD.getNumber(), 999));

                playerController.getBattleData().setTeamNo(battleDetail.getTeamNo(playerController.getObjectIndex()));
//                LogUtils.info("战斗服务器通知主服务器战斗开始 ->" + battleDetail.showInfo());
                playerController.setStatus(E_PlayerStatus.BATTLE_ING);
                playerController.serverDestroy();

                if(battleDetail.getBattleDetailType() == E_BattleDetailType.PVP_WORLD_MAP.getCode())
                    playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_START_MAP);
                else
                    playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_START);
            }

            if(battleDetail.getBattleDetailType() == E_BattleDetailType.PVP_WORLD_MAP.getCode())
            {
                PlayerController targetController = worldManager.getPlayerController(battleDetail.getTeam2Info().getIndexInfo());
                if (targetController != null && targetController.getBattleData() != null)
                {
                    targetController.getBattleData().setTeamNo(battleDetail.getTeamNo(targetController.getObjectIndex()));
//                    LogUtils.info("战斗服务器通知主服务器战斗开始 ->" + battleDetail.showInfo());
                    targetController.setStatus(E_PlayerStatus.BATTLE_ING);
                    targetController.serverDestroy();

                    targetController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_START_MAP);
                }
            }
        }
        else
        {
            LogUtils.error("serverInfo is null -> " + battleDetail.getServerId());
        }
    }

    @Override
    public void campBattleStart(int battleType, String playerIndex, int teamNo) throws RemoteException
    {
        //从活动服发过来的战斗开始
        WorldManager worldManager = GameServer.getInstance().getWorldManager();
        PlayerController playerController = worldManager.getPlayerController(playerIndex);
        LogUtils.info("活动服务器发来战斗开始 -> battleType" + battleType + ", playerIndex->" + playerIndex + ", teamNo");
        if (playerController != null && playerController.getBattleData() != null)
        {
            LogUtils.info("活动服务器发来战斗开始 -> " + playerController.getName());

            playerController.getBattleData().setTeamNo(teamNo);
//            worldManager.clearPlayerBattleTemp(battleType, playerIndex);

            playerController.setStatus(E_PlayerStatus.BATTLE_ING);
            playerController.serverDestroy();

            playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_START_CAMP);
        }
    }

    @Override
    public BattleResultParam battleEnd(BattleDetail battleDetail) throws RemoteException
    {
        ServerInfoBattle serverInfo = ServerManager.getInstance().getBattleServerInfo(battleDetail.getServerId());

        BattleResultParam param = new BattleResultParam();
        if (serverInfo != null)
        {
            if(serverInfo.isHaveAddRecord(battleDetail) && serverInfo.getBattle(battleDetail) == null)
            {
                LogUtils.error("已经结算过了 -> " + battleDetail.showInfo() + "  battleDetailType:" + battleDetail.getBattleDetailType());
                return param;
            }

            LogUtils.info("收到战斗服务器发来的战斗结束消息:" + battleDetail.showInfo());

            WorldManager worldManager = GameServer.getInstance().getWorldManager();

            int battleType = battleDetail.getBattleType();
            E_BattleDetailType battleDetailType = E_BattleDetailType.forNumber(battleDetail.getBattleDetailType());
            if(battleDetailType.isPlayerBattle())
            {
                PlayerController playerController = worldManager.getPlayerController(battleDetail.getTeam1Info().getIndexInfo());
                if(playerController == null)
                {
                    playerController = worldManager.getBattleCachePlayer(battleDetail.getTeam1Info().getIndexInfo());
                    LogUtils.error("战斗结束时玩家已经不在线,从战斗缓存里再获取一次,流水号 -> " + battleDetail.getTeam1Info().getIndexInfo() + " -> " + (playerController==null?"还是为空":playerController.getName()));
                }
                LogUtils.debug("获取到玩家数据:" + playerController + "   " + battleDetail.getTeam1Info().getIndexInfo());
                if (playerController != null)
                {
                    boolean team1Win = battleDetail.getWinTeam() == ConstantFactory.BATTLE_TEAM_1;

                    BattleTemp team2Info = battleDetail.getTeam2Info();
                    if (battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_INSTANCE_VALUE)
                    {
                        int levelId = Integer.parseInt(team2Info.getIndexInfo().split("_")[0]);
                        LevelConfig levelConfig = DataFactory.getInstance().getGameObject(DataFactory.LEVEL_KEY, levelId);
                        if (levelConfig != null) {
                            byte[] data = SGChallengeProto.C2S_PassLevel.newBuilder()
                                    .setChapterId(levelConfig.getInstanceId())
                                    .setLevelId(levelId)
                                    .setStarts(battleDetail.getTeam1Info().getStar())
                                    .build().toByteArray();
                            try {
                                SpringContext.getMessageChannel(ChallengeMsgChannel.class).messageChannel(
                                        SGMainProto.E_MSG_ID.MsgID_Instance_PassLevel_VALUE, playerController, data);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            LogUtils.info("副本战参数错误:" + team2Info);
                        }
                    }
                    else if (battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_ARENA_VALUE)
                    {
                        ChallengeMsgChannel arenaMsgChannel = (ChallengeMsgChannel) SpringContext.getMessageChannel(ChallengeMsgChannel.class);
                        arenaMsgChannel.arenaBattleEnd(playerController, team2Info.getIndexInfo(), team1Win);
                    }
                    else if (battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_OFFICIAL_RANK_VALUE)
                    {
                        ChallengeMsgChannel msgChannel = (ChallengeMsgChannel) SpringContext.getMessageChannel(ChallengeMsgChannel.class);
                        String[] str = team2Info.getIndexInfo().split(ConstantFactory.UNDERLINE);
                        msgChannel.challengeResult(playerController, Integer.parseInt(str[0]), Integer.parseInt(str[1]), team1Win);
                    }
                    else if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_HERO_TEMPLE_VALUE)
                    {
                        ChallengeMsgChannel msgChannel = (ChallengeMsgChannel) SpringContext.getMessageChannel(ChallengeMsgChannel.class);
                        msgChannel.heroTempleChallengeResult(playerController, Integer.parseInt(team2Info.getIndexInfo()), team1Win);
                    }
                    else if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_EXPEDITION_VALUE)
                    {
                        ChallengeMsgChannel msgChannel = (ChallengeMsgChannel) SpringContext.getMessageChannel(ChallengeMsgChannel.class);
                        msgChannel.expeditionChallengeResult(playerController, Integer.parseInt(team2Info.getIndexInfo()), team1Win);
                    }
                    else if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_MAJOR_VALUE)
                    {
                        MajorMsgChannel msgChannel = (MajorMsgChannel) SpringContext.getMessageChannel(MajorMsgChannel.class);
                        GoodsData[] goodsDatas = msgChannel.majorBattleEnd(playerController, team2Info.getIndexInfo(), team1Win);
                        param.addReward(goodsDatas);
                    }
                    else if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_WORLD_BOSS_VALUE)
                    {
                        /**
                         * 2018 8 14 注释掉boss战结束时的奖励
                         */
                        ChallengeMsgChannel msgChannel = (ChallengeMsgChannel) SpringContext.getMessageChannel(ChallengeMsgChannel.class);
                        WorldBossConfig config = DataFactory.getInstance().getGameObject(DataFactory.WORLD_BOSS_KEY, Integer.valueOf(team2Info.getIndexInfo()));
                        //param.addReward(config.passReward);
                        TwoTuple<Integer, String> result = WorldInfoFactory.getInstance().getWorldBossData().calculateDamageRate(battleDetail.getTeam1Info());
//                        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.BOSS_CHALLENGE_PRODUCT.getCode());
//                        if(stableDataConfig != null){
//                            param.addReward(new GoodsData(stableDataConfig.goods[0].type,
//                                    stableDataConfig.goods[0].id, result.getFirst()));
//                        }else {
//                            LogUtils.debug("StableDataConfig id error : " + E_StableDataType.BOSS_CHALLENGE_PRODUCT.getCode());
//                        }

                        msgChannel.worldBossBattleEnd(playerController, team2Info.getIndexInfo(), battleDetail, team1Win,new GoodsData[0], result.getFirst(), result.getSecond());
                    }
                    else if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_WORLD_MAP_VALUE)
                    {
                        worldMapBattleEnd(battleDetail);
                    }

                    if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_WORLD_MAP_VALUE)
                        playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_END_MAP);
                    else
                        playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_END);
                    playerController.clearBattle();
                }
                else
                {
                    LogUtils.error("战斗结束时玩家已经不在线 -> " + battleDetail.getTeam1Info().getIndexInfo());
                }
            }
            else
            {
                if(battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_WORLD_MAP_VALUE)
                {
                    worldMapBattleEnd(battleDetail);
                }
                else
                {
                    LogUtils.error("数据战，战斗类型错误 -> battleType:" + battleType + "  battleDetailType:" + battleDetailType);
                }
            }

            serverInfo.removeBattle(battleDetail);
        }
        else
        {
            LogUtils.error("战斗结束，serverInfo为空 -> " + battleDetail.getServerId());
        }

        return param;
    }

    private void worldMapBattleEnd(BattleDetail battleDetail)
    {
        String team1Index = battleDetail.getTeam1Info().getIndexInfo();
        String team2Index = battleDetail.getTeam2Info().getIndexInfo();
        //处理占领
        String masterPlayerIndex = "";
        if(battleDetail.getInitParam() instanceof BattleInitParamWorldMap)
            masterPlayerIndex = ((BattleInitParamWorldMap) battleDetail.getInitParam()).getMasterPlayerIndex();
        WorldMapData worldMapData = WorldInfoFactory.getInstance().getWorldMapData(masterPlayerIndex);
        if(worldMapData == null)
        {
            LogUtils.warn("单人战场数据已销毁,不进行结算处理 -> " + masterPlayerIndex);
            return;
        }

        if(battleDetail.getInitParam() instanceof BattleInitParamWorldMap)
        {
            BattleInitParamWorldMap initParam = (BattleInitParamWorldMap) battleDetail.getInitParam();
            CityBean cityBean = worldMapData.getCity(initParam.getCityId());
            if(cityBean != null)
            {
                SpriteBean winner = null, loser = null;
                BattleTemp winnerBattleTemp = null, loserBattleTemp = null;
                if(battleDetail.getWinTeam() == ConstantFactory.BATTLE_TEAM_1)
                {
                    winner = cityBean.getSpriteBean(team1Index);
                    loser = cityBean.getSpriteBean(team2Index);
                    winnerBattleTemp = battleDetail.getTeam1Info();
                    loserBattleTemp = battleDetail.getTeam2Info();
                }
                else
                {
                    winner = cityBean.getSpriteBean(team2Index);
                    loser = cityBean.getSpriteBean(team1Index);
                    winnerBattleTemp = battleDetail.getTeam2Info();
                    loserBattleTemp = battleDetail.getTeam1Info();
                }

                List<Player> offlinePlayerList = new CopyOnWriteArrayList<>();

                if (winner != null && loser != null)
                    WorldMapUtils.battleEnd(battleDetail.getId(), winner, loser, cityBean, battleDetail.getBattleDetailType(), winnerBattleTemp, loserBattleTemp, offlinePlayerList);
                else
                {
                    LogUtils.error("大地图结算数据异常 -> battleDetail -> " + battleDetail);
                    LogUtils.error("大地图结算数据异常 -> 当前城数据 -> 是否单人战场:" + worldMapData.isSingle() + " cityBean:" + cityBean);
                    LogUtils.error("大地图结算数据异常 -> winner:" + winner + "  loser:" + loser + " city:" + cityBean.getConfig().getName());
                    LogUtils.error("大地图结算数据异常 -> team1当前所在城:" + worldMapData.getSpriteCurCity(team1Index) + " team2当前所在城:" + worldMapData.getSpriteCurCity(team2Index));
                }

                GameServer.getInstance().savePlayerList(offlinePlayerList, true, ChallengeInfo.class, TaskInfo.class, SettingInfo.class, BagInfo.class);
            }
            else
            {
                LogUtils.error("大地图数据异常 -> 城不存在:" + initParam.getCityId());
            }
        }
        else
        {
            LogUtils.error("大地图战斗数据异常 -> " + battleDetail.getInitParam());
        }
    }


    @Override
    public BattleResultParamCampSingle campBattleEnd(int battleDetailType, boolean win, BattleTemp battleTemp, MatchBaseInfo target, String playerIndex) throws RemoteException
    {
        String playerObjectIndex = battleTemp == null ? playerIndex : battleTemp.getIndexInfo();
        LogUtils.info("主服收到活动服发来的战斗结束通知 -> " + playerObjectIndex);
        //从活动服发过来的战斗结束
        WorldManager worldManager = GameServer.getInstance().getWorldManager();

        BattleResultParamCampSingle result = null;
        TwoTuple<Player, PlayerController> playerResult = worldManager.getPlayerResult(playerObjectIndex);
        PlayerController playerController = playerResult.getSecond();
        Player player = playerController != null ? playerController.getPlayer() : playerResult.getFirst();
        if(player != null)
        {
            result = ActivityCampManager.getInstance().directEndCampBattle(win, player, target, battleTemp);

            if(playerController != null)
            {
                playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.BATTLE_END_CAMP);
                playerController.clearBattle();
            }
            else
            {
                if(result.getAddExploit() > 0)
                    GameServer.getInstance().savePlayerSync(player, true, ChallengeInfo.class, BagInfo.class);
                else
                    GameServer.getInstance().savePlayerSync(player, false, ChallengeInfo.class);
            }
        }

        return result;
    }

    @Override
    public void directEndBattle(DirectEndData directEndData) throws RemoteException{
        //异常情况，直接结束战斗,目前只有阵营战这样处理
    }


    @Override
    public void updateStatus(String playerIndex, String status) throws RemoteException
    {
        PlayerController playerController = GameServer.getInstance().getWorldManager().getPlayerController(playerIndex);
        if (playerController != null) {
            playerController.setStatus(E_PlayerStatus.valueOf(status));
            playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.UPDATE_STATUS);
        }
    }

//    @Override
//    public void updateStatusByPlayers(String status, List<String> playerIndexList) throws RemoteException {
//        for(String playerIndex : playerIndexList)
//        {
//            PlayerController playerController = GameServer.getInstance().getWorldManager().getPlayerController(playerIndex);
//            if (playerController != null)
//            {
//                playerController.setStatus(E_PlayerStatus.valueOf(status));
//                playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.UPDATE_STATUS);
//            }
//        }
//
//    }


    @Override
    public Player getOnlinePlayer(String playerIndex) throws RemoteException {
        PlayerController playerController = GameServer.getInstance().getWorldManager().getPlayerController(playerIndex);
        LogUtils.info("战斗服来获取在线玩家信息 -> " + playerController);
        if (playerController != null) {
            return playerController.getPlayer();
        }

        return null;
    }

    @Override
     public Player getOfflinePlayer(String playerIndex) throws RemoteException {
        ReadPlayerMapper playerMapper = SpringContext.getBean(ReadPlayerMapper.class);
        PlayerModel playerModel = playerMapper.getPlayerByIndex(playerIndex);
        if (playerModel != null) {

            return new Player(playerModel);
        }
        return null;
    }

    @Override
    public Player getPlayer(String playerIndex) throws RemoteException {
        Player player = getOnlinePlayer(playerIndex);
        if(player == null)
            player = getOfflinePlayer(playerIndex);

        return player;
    }

    @Override
    public DataFactory getDataFactory() throws RemoteException {
        return DataFactory.getInstance();
    }

    @Override
    public BattleTemp getBattleTemp(int battleType, String objectIndex, String... masterPlayerIndex) throws RemoteException
    {
        return GameServer.getInstance().getWorldManager().getSpriteBattleTemp(battleType, objectIndex, masterPlayerIndex);
    }


    @Override
    public boolean checkCampBattle(String playerIndex) throws RemoteException
    {
        PlayerController playerController = GameServer.getInstance().getWorldManager().getPlayerController(playerIndex);
        return playerController != null && playerController.getTcpConnection() != null && (playerController.getStatus() == E_PlayerStatus.FREE || playerController.getStatus() == E_PlayerStatus.CAMP_BATTLE_MATCH_SUCCESS);
    }

    @Override
    public String test() throws RemoteException {

        try {
            LogUtils.info("休息3秒");
            Thread.sleep(3000);
            LogUtils.info("休息完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void battleErrorEnd(List<String> playerIndexList) throws RemoteException {
        for(String playerIndex : playerIndexList)
        {
            PlayerController playerController = GameServer.getInstance().getWorldManager().getPlayerController(playerIndex);
            if (playerController != null && playerController.getBattleData() != null)
            {
                LogUtils.warn("战斗一直没有创建成功，现在作容错处理 -> " + playerController.getName() + "  data:" + playerController.getBattleData());
                playerController.clearBattle();
                playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.UPDATE_STATUS);
            }
        }
    }

    /**
     * 战斗异常结束 比如一直没连接战斗服务器
     * @param errorEndParamList
     * @throws RemoteException
     */
    @Override
    public void mapBattleErrorEnd(List<ErrorEndParam> errorEndParamList) throws RemoteException
    {
        LogUtils.warn("大地图战斗异常结束 -> " + errorEndParamList);
        WorldMapData worldMapData = null;
        PlayerController playerController = null;
        for(ErrorEndParam errorEndParam : errorEndParamList)
        {
            worldMapData = WorldInfoFactory.getInstance().getWorldMapData(errorEndParam.getMasterIndex());
            if(worldMapData != null)
            {
                CityBean cityBean = worldMapData.getCity(errorEndParam.getCityId());
                if(cityBean != null)
                {
                    SpriteBean spriteBean = cityBean.getSpriteBean(errorEndParam.getPlayerIndex());
                    SpriteBean targetBean = cityBean.getSpriteBean(errorEndParam.getTargetIndex());
                    if(spriteBean != null && targetBean != null)
                    {
                        if(spriteBean instanceof SpritePlayerBean)
                        {
                            playerController = ((SpritePlayerBean) spriteBean).getPlayerController();
                            if(playerController != null)
                            {
                                playerController.clearBattle();
                                playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.UPDATE_STATUS);
                            }
                        }
                        if(targetBean instanceof SpritePlayerBean)
                        {
                            playerController = ((SpritePlayerBean) targetBean).getPlayerController();
                            if(playerController != null)
                            {
                                playerController.clearBattle();
                                playerController.setLastUpdate(DataFactory.currentTime, 0, E_PlayerLastUpdate.UPDATE_STATUS);
                            }
                        }

                        if(spriteBean.getBaseInfo().getFc() > targetBean.getBaseInfo().getFc())
                        {
                            cityBean.leave(targetBean, spriteBean, E_CityInOutType.OUT_BATTLE_BY_ERROR);
                        }
                        else
                        {
                            cityBean.leave(spriteBean, targetBean, E_CityInOutType.OUT_BATTLE_BY_ERROR);
                        }
                    }
                }
            }

        }
    }
}
